package com.zhoug.fileselector3.beans;


import com.zhoug.common3.content.FileType;
import com.zhoug.common3.utils.FileUtils;
import com.zhoug.common3.utils.StringUtils;
import com.zhoug.common3.utils.file.IFile;

import java.io.Serializable;

/**
 * 本地媒体文件
 * @Author HK-LJJ
 * @Date 2020/1/6
 * @Description
 */
public class LocalMedia implements IFile, Serializable {
    /**
     * 文件路径
     */
    private String path;

    /**
     * 文件名(主要用于音视频)
     */
    private String name;
    /**
     * 文件大小
     */
    private long size;
    /**
     * 可播放文件(视频/音频)的总时长.单位毫秒
     */
    private long duration;

    /**
     * 宽
     */
    private int width;

    /**
     * 高
     */
    private int height;
    /**
     * 是否从拍照获取的
     */
    private boolean isFromCamera;
    /**
     * 修改时间
     */
    private String modifiedDate;

    /**
     * 文件类型
     */
    @FileType.Type
    private int fileType;

    private String mimeType;

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public boolean isFromCamera() {
        return isFromCamera;
    }

    public void setFromCamera(boolean fromCamera) {
        isFromCamera = fromCamera;
    }

    public String getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(String modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public int getFileType() {
        if (fileType == 0) {
            fileType = FileType.getType(path);
        }

        return fileType;
    }

    /**
     * 获取文件真实地址
     *
     * @return
     */
    @Override
    public String getRealUrl() {
        return path;
    }

    /**
     * 文件后缀
     *
     * @return
     */
    @Override
    public String getFileSuffix() {
        String suffix = FileUtils.getSuffix(path);
        return StringUtils.isNullOrEmpty(suffix) ? null : "." + suffix;
    }

    /**
     * 获取文件名
     *
     * @return
     */
    @Override
    public String getFileName() {
        return FileUtils.getNameWithSuffix(path);
    }

    public void setFileType(@FileType.Type int fileType) {
        this.fileType = fileType;
    }

    public String getMimeType() {
        if(mimeType==null && path!=null){
            mimeType=FileType.getMimeType(path);
        }
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    @Override
    public String toString() {
        return "LocalMedia{" +
                "path='" + path + '\'' +
                ", name='" + name + '\'' +
                ", size=" + size +
                ", duration=" + duration +
                ", width=" + width +
                ", height=" + height +
                ", isFromCamera=" + isFromCamera +
                ", modifiedDate='" + modifiedDate + '\'' +
                ", fileType=" + fileType +
                ", mimeType='" + mimeType + '\'' +
                '}';
    }
}
